package com.sysu;

import com.sysu.dao.UserDao;
import com.sysu.pojo.User;
import com.sysu.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class Main {
    //第一步：获得sqlSession对象
    static SqlSession sqlSession;
    public static void main(String[] args) {
        try {

            sqlSession = MybatisUtils.getSqlSession();
            //方式一：getMapper
            UserDao mapper = sqlSession.getMapper(UserDao.class);
            List<User> userList = mapper.getUserList();
            for (User user : userList) {
                System.out.println(user);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            //关闭sqlSession
            sqlSession.close();
        }
    }
}
